<!--
 * @description: 
 * @LastEditTime: 2024-02-28 15:21:10
-->
<template>
  <view class="list-page b-w">
    <u-list @scrolltolower="scrolltolower">
      <view class="list-search">
        <u-search
          placeholder="请输入关键词搜索"
          v-model="keyword"
          @clear="clearSearch"
          @custom="searchList"
          @search="searchList"
        ></u-search>
      </view>
      <u-list-item v-for="(item, index) in listData" :key="index">
        <u-cell :title="item.userName" isLink @click="toUserDetail(item.id)">
          <u-avatar
            slot="icon"
            size="35"
            :src="item.avatar"
            customStyle="margin: -3px 5px -3px 0"
          ></u-avatar>
        </u-cell>
      </u-list-item>
    </u-list>
  </view>
</template>

<script>
export default {
  data() {
    return {
      listIdentifying: '',
      keyword: '',
      pageNo: 1,
      pageSize: 20,
      total: 0,
      listData: [],
    }
  },
  onLoad(options) {
    this.listIdentifying = options.type || 'professional'
    uni.setNavigationBarTitle({
      title:
        options.type === 'professional'
          ? '专家列表'
          : options.type === 'enterprise'
          ? '企业列表'
          : '经理人列表',
    })
    this.getUserList()
  },
  methods: {
    scrolltolower() {
      let totalPageNo = Math.ceil(this.total / this.pageSize)
      if (this.pageNo < totalPageNo) {
        ++this.pageNo
        this.getUserList()
      }
    },
    searchList(e) {
      this.keyword = e
      this.pageNo = 1
      this.getUserList()
    },
    clearSearch() {
      this.keyword = ''
      this.pageNo = 1
      this.getUserList()
    },
    getUserList() {
      this.$request('/user/userPage', {
        keyword: this.keyword,
        identifying: this.listIdentifying,
        pageNo: this.pageNo,
        pageSize: this.pageSize,
      }).then((res) => {
        if (this.pageNo === 1) this.listData = []
        this.listData = [...this.listData, ...res.result.records]
        this.total = res.result.total
      })
    },
    toUserDetail(id) {
      let url = ''
      if (this.listIdentifying == 'professional') {
        url = `/pages/form/workerForm`
      } else if (this.listIdentifying == 'enterprise') {
        url = `/pages/form/company`
      } else {
        url = `/pages/form/manager`
      }
      url += `?userId=${id}`
      this.$routeUtils.navigateTo({ url })
    },
  },
}
</script>
<style lang="scss" scoped>
.list-page {
  .list-search {
    padding: 20rpx;
  }
}
</style>
